import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '@/views/HomeView.vue'
import ServerList from '@/views/asset/ServerList.vue'
import ServerDetailPage from '@/views/asset/ServerDetailPage.vue'
import RoomList from '@/views/asset/RoomList.vue'
import CabinetList from '@/views/asset/CabinetList.vue'
import RoomConfig from '@/views/settings/RoomConfig.vue'
import ScriptManager from '@/views/task/ScriptManager.vue'
import TaskManager from '@/views/task/TaskManager.vue'
import WorkflowList from '@/views/task/WorkflowList.vue'
import TaskLayout from '@/views/task/TaskLayout.vue'
import ServerDeploy from '@/views/asset/ServerDeploy.vue'
import SSHTerminal from '@/views/ssh/SSHTerminal.vue'
import type { RouteRecordRaw } from 'vue-router'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    meta: {
      title: '首页',
      icon: 'House',
    },
  },
  {
    path: '/asset/server',
    name: 'server-list',
    component: ServerList,
    meta: { title: '服务器管理' },
  },
  {
    path: '/asset/server/:id',
    name: 'server-detail',
    component: ServerDetailPage,
    meta: { title: '服务器详情' },
  },
  {
    path: '/asset/datacenter',
    name: 'room-list',
    component: RoomList,
    meta: { title: '机房管理' },
  },
  {
    path: '/asset/cabinet',
    name: 'cabinet-list',
    component: CabinetList,
    meta: { title: '机柜管理' },
  },
  {
    path: '/settings/room-config',
    name: 'room-config',
    component: RoomConfig,
    meta: { title: '机房配置' },
  },
  {
    path: '/task/scripts',
    name: 'script-manager',
    component: ScriptManager,
    meta: { title: '脚本管理' },
  },
  {
    path: '/task',
    component: TaskLayout,
    children: [
      {
        path: 'list',
        name: 'taskList',
        component: TaskManager,
        meta: { title: '任务管理' },
      },
      {
        path: 'workflow',
        name: 'workflowList',
        component: WorkflowList,
        meta: { title: '工作流管理' },
      },
      {
        path: 'workflow/:id',
        name: 'workflowDetail',
        component: () => import('@/views/task/WorkflowDetail.vue'),
        meta: { title: '工作流详情' },
      },
      {
        path: 'workflow/create',
        name: 'workflowCreate',
        component: () => import('@/views/task/WorkflowEdit.vue'),
        meta: { title: '创建工作流' },
      },
      {
        path: 'workflow/edit/:id',
        name: 'workflowEdit',
        component: () => import('@/views/task/WorkflowEdit.vue'),
        meta: { title: '编辑工作流' },
      },
      {
        path: 'create',
        name: 'taskCreate',
        component: () => import('@/views/task/TaskCreate.vue'),
        meta: { title: '创建任务' },
      },
    ],
  },
  {
    path: '/asset/deploy',
    name: 'server-deploy',
    component: ServerDeploy,
    meta: { title: '自动化部署' },
  },
  {
    path: '/ssh',
    name: 'ssh-terminal',
    component: SSHTerminal,
    meta: { title: 'SSH终端' },
  },
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: routes,
})

export default router
